'use strict';
dataloaderApp.controller ('AddSchedulerCtrl' , [ '$scope', '$rootScope', '$route','$routeParams' , '$location',  '$filter' , 'scheduleServices'
		, function ( $scope, $rootScope, $route, $routeParams , $location,  $filter , scheduleServices) {

	$scope.job = {};
	$scope.jobs = [];
	$scope.successfullyExecuted = false;
	
	$scope.allJobs = function () {
		scheduleServices.findAllJobs ().then(function (response) {
			
			$scope.jobs = response;
			
			setTimeout(function () {   
				$scope.allJobs();
	   			$scope.$apply();
			},15000);

		
		});
		
	};

	$scope.add = function () {
		if (!$scope.job) return;
		
		var job = {
			startDate : moment ( $scope.job.date + $scope.job.time , 'DD/MM/YYYYHH:mm').format ("YYYY-MM-DD HH:mm:ss")
			, type : 'RUN_ONE_A_DAY'		
		}
		
		scheduleServices.save (job).then(function (response) {
			
			$scope.successfullyExecuted = true;
			
			$scope.jobs = response;
			
		});
	};
 	
	
	
			
			
}]);
